package com.dosen.api.third.party.cmp.utils;


import com.dosen.api.third.party.cmp.client.CmpClient;
import com.dosen.api.third.party.cmp.model.vhostinfo.CmpVHost;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @version V1.0
 * @author: guangcheng
 * @date: 2023/1/12 17:39
 * @description:
 */
@Component
public class CmpCacheUpdate {
    Logger log = LoggerFactory.getLogger(CmpCacheUpdate.class);

    @Autowired
    CmpClient cmpClient;

    @Scheduled(cron = "0 0,30 * * * ?")
    public void run0() {
        log.info("\n cmp token update");
        cmpClient.getLoginData();
    }

    @Scheduled(cron = "0 0 * * * ?")
    public void run1() {
        log.info("\n cmp vms update");
        List<CmpVHost> cmpVHosts = cmpClient.cmpAllVm();
        CmpVmsCache.CMP_VMS_CACHE.put("cmp", cmpVHosts);
    }

}

